<?php
namespace module\manage\middleware;

use app\Request;
// use think\exception\HttpException;

class Perm
{
    public function handle(Request $request, \Closure $next)
    {
        $perm = $request->controller() . ':' . $request->action();
        $role = Role::where('id', $request->role_id)->findOrEmpty();
        if($role->isEmpty()){
            return json(['code' => 403, 'msg' => '当前角色不存在']);
        }
        if(!in_array($perm, $role->perms)){
            return json(['code' => 403, 'msg' => '当您没有当前权限']);
        }
        return $next($request);
    }
}